//
//  BKTabBarController.swift
//  微博
//
//  Created by mac on 16/8/8.
//  Copyright © 2016年 xbk. All rights reserved.
//

import UIKit

class BKTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //view.backgroundColor = UIColor.redColor()
        
        let bkTabBar = BKTabBar()
        
        bkTabBar.composeButtonClosure = {[weak self] in

            self?.compose()
        }
        
        
        setValue(bkTabBar, forKey: "tabBar")
        
        
        //添加子视图控制器
        addChildViewController(BKHomeTableViewController(), imagName: "tabbar_home", title: "首页")
        addChildViewController(BKMessageTableViewController(), imagName: "tabbar_message_center", title: "消息")
        addChildViewController(BKDiscoverTableViewController(), imagName: "tabbar_discover", title: "发现")
        addChildViewController(BKProfileTableViewController(), imagName: "tabbar_profile", title: "我的")
        
        
    }
    //进入发微博的界面
    private func compose (){
        
        let composeVC = BKComposeViewController()
        let nav = UINavigationController(rootViewController: composeVC)
        presentViewController(nav, animated: true, completion: nil)
    }
    
    
    //重载添加子控制器
    func addChildViewController(childController: UIViewController,imagName:String,title:String) {
        
        childController.tabBarItem.image = UIImage(named:imagName)
        childController.tabBarItem.selectedImage = UIImage(named:"\(imagName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        childController.title = title
        
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFontOfSize(14)], forState: .Normal)
        
        
        //添加到导航控制器
        let nav = UINavigationController(rootViewController: childController)
        
        addChildViewController(nav)
    }

}
